package com.hns.can.master.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hns.can.base.entity.SysRoleEntity;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.master.entity.CommCarCurrentLoInfoEntity;
import com.hns.can.master.vo.CarCountVo;
import com.hns.can.master.vo.HomeFactoryAreaCarVo;
import com.hns.can.master.vo.HomeFactoryCarPositionListVo;
import com.hns.can.master.vo.HomeFactoryFaultRankVo;
import com.hns.can.master.vo.HomeFactoryIndexVo;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
/**
 * 车厂主页service
 * @author:zhangyu
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Service
public class HomeFactoryWholeService extends CommonService {
	
	@Autowired
    private FillCodeDscValue codeDscValue;
	
	@SuppressWarnings("unchecked")
	public HomeFactoryIndexVo getTotalIndex(Map map){
		List<HomeFactoryIndexVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("homeFactory.getTotalIndex", map), HomeFactoryIndexVo.class);
		if(PubUtil.isNotEmpty(list)){
			return list.get(0);
		}else{
			return null;
		}
	}

	@SuppressWarnings("unchecked")
	public List<HomeFactoryFaultRankVo> getFaultRanking(Map map) {
		List<HomeFactoryFaultRankVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("homeFactory.faultsRanking", map), HomeFactoryFaultRankVo.class);
		return list;
	}
	
	public List getAreaCar(List<SysRoleEntity> role, String userId){
		HashMap map = new HashMap();
		map.put("userId", userId);
		map.put("roleIdList", role);
		List list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("homeFactory.getAreaCarCount", map), HomeFactoryAreaCarVo.class);
		return list;
	}
	
	/**
     * @param vo
     * @return
     * @throws Exception
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     * @创建日期:2015-1-9
     * @功能说明：获取车的最终位置
     */
    public List<CommCarCurrentLoInfoEntity> getCarPositionList(Map map) throws Exception {
        List<CommCarCurrentLoInfoEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("homeFactory.getCarPositionList", map), HomeFactoryCarPositionListVo.class);
        return list;
    }
    
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
	public List getProvinceLocation(String corpId, List<SysRoleEntity> role, String userId){
		HashMap map = new HashMap();
		map.put("corpId", corpId);
		map.put("userId", userId);
		map.put("roleIdList", role);
		List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("homeFactory.getProvinceLocation", map), CarCountVo.class);
		Map<String,String> mapTmp = new HashMap<String,String>();
		mapTmp.put("provinceId", "ADS00000");
        codeDscValue.fillCodeDscValue(list, mapTmp);
        return list;
	}
    
    @SuppressWarnings({ "rawtypes", "unchecked"})
	public List getCityLocation(String corpId, List<SysRoleEntity> role, String userId){
		HashMap map = new HashMap();
		map.put("corpId", corpId);
		map.put("userId", userId);
		map.put("roleIdList", role);
		List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("homeFactory.getCityLocation", map), CarCountVo.class);
        return list;
	}
    
}
